/**
 * @file led_drv_pin.c
 * @author Jason Wen (embediot@163.com)
 * @brief 使用MCU引脚直接驱动LED
 * @version 0.1
 * @date 2024-06-07
 * 
 * @copyright EmbedIoT Studio Copyright (c) 2024
 * 
 */

#include "led_drv_pin.h"
#include "stddef.h"

led_drv_pin_t led_drv_pin;

//初始化MCU引脚
static void mcu_gpio_init(void)
{
    //在这里初始化各个LED灯引脚
}

static void set_gpio_high(unsigned char gpio_num)
{
    //在这里设置指定的GPIO高电平
}

static void set_gpio_low(unsigned char gpio_num)
{
    //在这里设置指定的GPIO低电平
}

static int _init(void *_this)
{
    int ret = 0;

    mcu_gpio_init();

    return ret;
}

static int _turn_on(void *_this, led_id_t id)
{
    int ret = 0;

    if(NULL == _this)return -1;

    led_drv_pin_t *drv_pin = (led_drv_pin_t *)_this;

    set_gpio_high(id);

    drv_pin->state[id] = 1;    

    return ret;
}

static int _turn_off(void *_this, led_id_t id)
{
    int ret = 0;

    if(NULL == _this)return -1;

    led_drv_pin_t *drv_pin = (led_drv_pin_t *)_this;

    set_gpio_low(id);

    drv_pin->state[id] = 0;    

    return ret;
}

//引脚高低电平驱动不支持设置亮度
static int _set_brightness(void *_this, led_id_t id, unsigned char level)
{
    int ret = -1;

    return ret;
}

//引脚高低电平驱动不不支持设置颜色
static int _set_color(void *_this, led_id_t id, rgbcw_t *color)
{
    int ret = -1;

    return ret;
}


static int _toggle(void *_this, led_id_t id)
{
    int ret = 0;

    if(NULL == _this)return -1;

    led_drv_pin_t *drv_pin = (led_drv_pin_t *)_this;

    if(drv_pin->state[id])set_gpio_low(id);
    else set_gpio_high(id);

    return ret;
}

led_drv_pin_t *led_drv_pin_create(void)
{
    //初始化驱动函数接口
    led_drv_pin.drv.init = _init;
    led_drv_pin.drv.turn_on = _turn_on;
    led_drv_pin.drv.turn_off = _turn_off;
    led_drv_pin.drv.toggle = _toggle;
    led_drv_pin.drv.set_brightness = NULL;
    led_drv_pin.drv.set_color = NULL;

    led_drv_pin.drv.led_count = LED_MAX_NUM;
    
    return &led_drv_pin;
}


